home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / CNews / Source / expire / histslash.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-19  |  839 b   |  44 lines

  1. /*
  2.  * Convert slashed filenames to dotted group/article names in a history
  3.  * file, for use in mkhistory.  Input comes only from stdin.
  4.  */
  5. #include <stdio.h>
  6. #include <assert.h>
  7. #include <string.h>
  8. #include "fgetmfs.h"
  9.  
  10. char *progname = "histslash";
  11.  
  12. main()
  13. {
  14.     register char *scan;
  15.     register char *last;
  16.     register char *line;
  17.  
  18.     while ((line = fgetms(stdin)) != NULL) {
  19.         scan = strchr(line, '\t');
  20.         if (scan != NULL)
  21.             scan = strchr(scan+1, '\t');
  22.         if (scan == NULL) {
  23.             complain("bad number of fields in `%s'", line);
  24.             exit(1);
  25.         }
  26.         scan++;
  27.         last = NULL;
  28.         while (*scan != '\0') {
  29.             if (*scan == '/') {
  30.                 *scan = '.';
  31.                 last = scan;
  32.             }
  33.             if (*scan == ' ' || *scan == '\n') {
  34.                 assert(last != NULL);
  35.                 *last = '/';
  36.             }
  37.             scan++;
  38.         }
  39.         if (fputs(line, stdout) == EOF)
  40.             error("fputs failed", "");
  41.         free(line);
  42.     }
  43. }
  44.